package com.nstc.ibd.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nstc.ibd.dao.CommonDao;
import com.nstc.ibd.model.NsClient;
import com.nstc.ibd.model.view.AssociateBankView;
import com.nstc.ibd.service.CommonService;
import com.nstc.ibd.util.CastUtil;

@Service("commonService")
public class CommonServiceImpl implements CommonService{
    
    
    private static Map<String, String> curCodeMap;
	
	@Autowired
	private CommonDao commonDao;
	
	public NsClient getNsclient(String cltName){
	    List<NsClient> list = commonDao.queryNsclientList(cltName);
	    if (list.size() >0) {
	        return list.get(0);
	    }
	    return null;
	}

    @Override
    public  String getCurCode(String curCodeName) {
        if (curCodeMap != null) {
            return curCodeMap.get(curCodeName);
        }
        curCodeMap = new HashMap<String, String>();
        List<Map<String,String>> curCodeList = commonDao.queryCurCodeList();
        for (Map<String, String> map : curCodeList) {
            String name = map.get("name");
            String value = map.get("value");
            curCodeMap.put(name, value);
        }
        return curCodeMap.get(curCodeName);
    }
    
    public AssociateBankView getAssociateBank(String accName){
        List<AssociateBankView> list = commonDao.queryAssociateBankList(accName);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
    
    public Double getExchangeRateByTargetno(String currencyNo, String targetno) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("currencyNo", currencyNo);
        map.put("targetno", targetno);
        List<Double> rateList = commonDao.getExchangeRateByTargetno(map);
        if (rateList.size() > 0){
            return CastUtil.toDouble(rateList.get(0),1);
        }
        return new Double(1);
    }
   
	
	

}
